﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Quality_Calculator.DataLoader
{
    public class CrafterData
    {
        public int Craftmanship { get; set; }
        public int Control { get; set; }
        public int CP { get; set; }
        public int Level { get; set; }
    }
    public class StatLoader
    {
        static public CrafterData LoadStats()
        {
            try
            {
                MemoryManager mem = new MemoryManager(GetProcessHandle("ffxiv"));
                UInt32 StatTable = (uint)mem.GetProcessModule("ffxiv.exe").BaseAddress + 0x10bd3f0;
                UInt32 Craftmanship = mem.ReadMemoryAsUint(StatTable + 0x46 * 4 + 0xfc);
                UInt32 Control = mem.ReadMemoryAsUint(StatTable + 0x47 * 4 + 0xfc);
                UInt32 CP = mem.ReadMemoryAsUint(StatTable + 0xb * 4 + 0xfc);
                //[15A495B0 + 20] = B = 154F64E0
                //[B + 78] = Control
                return new CrafterData() { Control = (int)Control, CP = (int)CP, Craftmanship = (int)Craftmanship };
            }
            catch (Exception e)
            {
                return new CrafterData();
            }
        }
        private static IntPtr GetProcessHandle(string processName)
        {
            Process[] p = Process.GetProcessesByName(processName);
            if (p.Length == 0)
                return IntPtr.Zero;
            else
                return p[0].MainWindowHandle;
        }
    }
}
